---authing app
-- @module
-- ===================================
-- default params
local d = Ding
local resty_url = require("resty.url")
local rpc_http_cli = require("apps.rpc.method").http
local meta_query = require("apps.rpc.method").meta_tostring

local AUTH_SETTING = require("apps.rpc.setting").authing
-- ===================================
local api_funcs = {}
local callback_funcs = import("./callback")


--==============
--三方登录-github
--===============
api_funcs.third_login_wx = function()


end

--============
--三方登录-微信
--============
api_funcs.third_login_wx = function()
    local querys = {
        client_id = AUTH_SETTING["client_id"],
        -- ext_idp_conn_id = ext_idp_wx,
        response_type = "code id_token access_token",
        -- redirect_uri = AUTH_SETTING["ext_idp_callback"],
        scope = "openid profile",
        state = ngx.md5(ngx.time())
    }
    setmetatable(querys, {
        __tostring = meta_query
    })
    dump(querys, "-->>queyrys")
    print(tostring(querys), '_->>>querys111')
    local r_url = resty_url.join(AUTH_SETTING["host"], string.format("/api/v3/signin-by-extidp?%s", tostring(querys)))
    -- r_url.join
    ngx.log(ngx.INFO, "final url is :", r_url)

    local res, err = rpc_http_cli():request_uri(r_url, {
        method = "GET"

    })
    if not res then
        ngx.log(ngx.ERR, "request failed: ", err)
        return
    end

    -- The `res` table contains the expeected `status`, `headers` and `body` fields.
    local status = res.status
    local length = res.headers["Content-Length"]
    local body = res.body

    dump(res, '____>>>login wx')
    dump(body, '____>>>login body')
    return res
end


return {
    cs = api_funcs, 
    sc = callback_funcs
}
